/*****************************************************************
*  Copyright (C) 2012  Marco Bavagnoli - lil.deimos@gmail.com    *
******************************************************************/

#ifndef OMGCAM_H
#define OMGCAM_H

#include <QDeclarativeItem>
#include <QCamera>

class cameraFeatures : public QDeclarativeItem
{
    Q_OBJECT
    Q_ENUMS(ExposureMode)
    Q_ENUMS(FlashMode)
    Q_ENUMS(State)
    Q_ENUMS(WhiteBalanceMode)

public:
    enum ExposureMode {
        ExposureAuto = QCameraExposure::ExposureAuto,
        ExposureManual = QCameraExposure::ExposureManual,
        ExposurePortrait = QCameraExposure::ExposurePortrait,
        ExposureNight = QCameraExposure::ExposureNight,
        ExposureBacklight = QCameraExposure::ExposureBacklight,
        ExposureSpotlight = QCameraExposure::ExposureSpotlight,
        ExposureSports = QCameraExposure::ExposureSports,
        ExposureSnow = QCameraExposure::ExposureSnow,
        ExposureBeach = QCameraExposure::ExposureBeach,
        ExposureLargeAperture = QCameraExposure::ExposureLargeAperture,
        ExposureSmallAperture = QCameraExposure::ExposureSmallAperture,
        ExposureModeVendor = QCameraExposure::ExposureModeVendor
    };

    enum FlashMode {
        FlashAuto = QCameraExposure::FlashAuto,
        FlashOff = QCameraExposure::FlashOff,
        FlashOn = QCameraExposure::FlashOn,
        FlashRedEyeReduction  = QCameraExposure::FlashRedEyeReduction,
        FlashFill = QCameraExposure::FlashFill,
        FlashTorch = QCameraExposure::FlashTorch,
        FlashSlowSyncFrontCurtain = QCameraExposure::FlashSlowSyncFrontCurtain,
        FlashSlowSyncRearCurtain = QCameraExposure::FlashSlowSyncRearCurtain,
        FlashManual = QCameraExposure::FlashManual
    };

    enum State {
        ActiveState = QCamera::ActiveState,
        LoadedState = QCamera::LoadedState,
        UnloadedState = QCamera::UnloadedState
    };

    enum WhiteBalanceMode {
        WhiteBalanceAuto = QCameraImageProcessing::WhiteBalanceAuto,
        WhiteBalanceManual = QCameraImageProcessing::WhiteBalanceManual,
        WhiteBalanceSunlight = QCameraImageProcessing::WhiteBalanceSunlight,
        WhiteBalanceCloudy = QCameraImageProcessing::WhiteBalanceCloudy,
        WhiteBalanceShade = QCameraImageProcessing::WhiteBalanceShade,
        WhiteBalanceTungsten = QCameraImageProcessing::WhiteBalanceTungsten,
        WhiteBalanceFluorescent = QCameraImageProcessing::WhiteBalanceFluorescent,
        WhiteBalanceIncandescent = QCameraImageProcessing::WhiteBalanceIncandescent,
        WhiteBalanceFlash = QCameraImageProcessing::WhiteBalanceFlash,
        WhiteBalanceSunset = QCameraImageProcessing::WhiteBalanceSunset,
        WhiteBalanceVendor = QCameraImageProcessing::WhiteBalanceVendor
    };

    explicit cameraFeatures(QDeclarativeItem *parent = 0);

    Q_INVOKABLE void startGetFeatures(QString device);
    Q_INVOKABLE QStringList getAvailableDevices();
    Q_INVOKABLE bool isExposureSupported(ExposureMode state);
    Q_INVOKABLE bool isFlashModeSupported(FlashMode state);
    Q_INVOKABLE bool isWhiteBalanceSupported(WhiteBalanceMode state);
    Q_INVOKABLE QList<int> getIsoModesSupportedList();
    Q_INVOKABLE QList<qreal> getSupportedAperturesList();
    Q_INVOKABLE QList<qreal> getSupportedShutterSpeedsList();
    Q_INVOKABLE QStringList getCompensationsModes();
    Q_INVOKABLE QList<QSize> getSupportedResolutionsList();

public slots:
    void getFeatures(QCamera::State state);

signals:
    void featuresRetrieved();

protected:
    QCamera *m_camera;
    bool m_featuredAcquired;
    QStringList availableDevices;
    QList<ExposureMode> availableExposures;
    QList<FlashMode> availableFlashModes;
    QList<WhiteBalanceMode> availableWhiteBalanceModes;
    QList<int> availableIsoModes;
    QList<qreal> availableApertureModes;
    QList<qreal> availableShutterSpeedModes;
    QStringList availableCompensationModes;
    QList<QSize> availableResolutionsSpeedModes;
};

#endif // OMGCAM_H
